#include "shellsort.h"
#include "swap.h"

#include <stdlib.h>
#include <string.h>

/*****************************************************************************/

void shellsort(char** words, int arraysize) {
    int i, e, k;

    for (k = arraysize/2; k >= 1; k /= 2) {
        for (i = 0; i < k; i++) {
            e = i;
            while (e+k < arraysize) {
                if (strcasecmp(words[e], words[e+k]) > 0) {
                    swap(&words[e], &words[e+k]);
                    if (e-k > 0) {
                        e -= k;
                    } else {
                        e += k;
                    }
                } else {
                    e += k;
                }
            }
        }
    }
}

/*****************************************************************************/

